#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>

using namespace std;
int main()
{
	int m, n;
	int a1[6][6];
	cin >> m >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin>>a1[i][j];
		}
	}


	//1 2 3 
	for (int i = 0; i < n; i++)
	{
		for (int k = 0; k < m; k++)
		{
			int tmp = a1[i][n - 1];
			for (int j = n - 1; j > 0; j--)
			{
				a1[i][j] = a1[i][j - 1];
			}
			a1[i][0] = tmp;
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cout << a1[i][j]<<" ";
		}
		cout << endl;
	}
	return 0;
}